

import 'package:flutter/material.dart';

class ShowUtils {
  static String getShowPrice(String? price) {
    if (isNumber(price)) {
      return (double.tryParse(price!)! / 100).toStringAsFixed(2);
    }
    return '0';
  }

  static bool isNumber(String? price) {
    return price == null ? false : num.tryParse(price) != null;
  }

  static ({String bigNum, String smallNum}) getShowPrices(String? price) {
    if (isNumber(price)) {
      final numS =
          ((double.tryParse(price!)! / 100).toStringAsFixed(2)).split(".");
      return (bigNum: numS[0], smallNum: numS[1]);
    }
    return (bigNum: "0", smallNum: "00");
  }

  static ({Color color, String text}) getTagInfo(int isDefault, String tag) {
    if (isDefault == 1) {
      return (text: "默认", color: Colors.red);
    } else {
      return (text: tag, color: Colors.blueAccent);
    }
  }

  static String showLineStr(String? data, {bool isPre = false}) {
    final dt = showSafeString(data);
    return isPre ? "\n$dt" : "$dt\n";
  }

  static String showSafeString(String? data) {
    return data ?? '';
  }
}
